package qlsl.androiddesign.view.subview.activityview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import qlsl.androiddesign.activity.subactivity.PublishTypeSecondActivity;
import qlsl.androiddesign.adapter.subadapter.PublishTypeSecondAdapter;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 论坛发布二级分类页<br/>
 * 需要传入的键：title,position<br/>
 * 传入的值类型： String，int<br/>
 * 传入的值含义：标题，位置<br/>
 * 是否必传 ：是
 */
public class PublishTypeSecondView extends FunctionView<PublishTypeSecondActivity> {

	private ListView listView;

	public PublishTypeSecondView(PublishTypeSecondActivity activity) {
		super(activity);
		setContentView(R.layout.activity_publish_type_second);
	}

	protected void initView(View view) {
		setTitle(activity.getIntent().getStringExtra("title"));
		listView = findViewById(R.id.listView);
	}

	protected void initData() {
		setListViewData();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.list_item:
			doClickListItem(view);
			break;
		}
	}

	@SuppressWarnings("unchecked")
	private void doClickListItem(View view) {
		int position = activity.getIntent().getIntExtra("position", 0);
		int clickPosition = listView.getPositionForView(view);
		String[] titles = new String[] { "JRZT", "ESPJ", "GZZX", "ZLFX" };
		HashMap<String, Object> map = (HashMap<String, Object>) listView.getAdapter().getItem(clickPosition);
		Intent intent = new Intent();
		intent.putExtra("cnfirstsection", titles[position]);
		intent.putExtra("firstsection", activity.getIntent().getStringExtra("title"));
		intent.putExtra("secondsection", (String) map.get("text"));
		intent.putExtra("cnsecondsection", (String) map.get("desc"));
		activity.setResult(0, intent);
		activity.finish();
	}

	private void setListViewData() {
		String[] descs_text_0 = new String[] { "杂谈图库", "志同道合", "快挖信息" };
		String[] descs_text_1 = new String[] { "出售", "求购" };
		String[] descs_text_2 = new String[] { "异动/振动", "漏油/漏水", "发动机冒烟", "高温", "电气/报警", "憋车/熄火", "动作慢", "没劲", "液压泵/阀",
				"回转", "行走", "油缸异常", "前端/结构件", "四轮一带", "其他" };
		String[] descs_text_3 = new String[] { "卡特", "小松", "加藤", "日立", "住友", "神钢", "久保田", "洋马", "竹内", "现代", "斗山", "三一",
				"中联", "山河", "柳工", "玉柴", "徐工", "沃尔沃", "三菱", "五十铃", "其他资料" };
		String[] descs_py_0 = new String[] { "ZTTK", "ZTDH", "KWXX" };
		String[] descs_py_1 = new String[] { "CS", "QG" };
		String[] descs_py_2 = new String[] { "YDZD", "LYLS", "FDJMY", "GW", "DQBJ", "BCXH", "DZM", "MJ", "YYB", "HZ",
				"XZ", "YGYC", "QDJGJ", "SLYD", "QT" };
		String[] descs_py_3 = new String[] { "KT", "XS", "JT", "RL", "ZY", "SG", "JBT", "YM", "ZN", "XD", "DS", "SY",
				"ZL", "SH", "LG", "YC", "XG", "WEW", "SL", "WSL", "QTZL" };

		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		int position = activity.getIntent().getIntExtra("position", 0);
		String[] texts = null;
		String[] descs = null;
		if (position == 0) {
			texts = descs_text_0;
			descs = descs_py_0;
		} else if (position == 1) {
			texts = descs_text_1;
			descs = descs_py_1;
		} else if (position == 2) {
			texts = descs_text_2;
			descs = descs_py_2;
		} else if (position == 3) {
			texts = descs_text_3;
			descs = descs_py_3;
		}
		for (int index = 0; index < texts.length; index++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("text", texts[index]);
			map.put("desc", descs[index]);
			list.add(map);
		}
		PublishTypeSecondAdapter adapter = new PublishTypeSecondAdapter(activity, list);
		listView.setAdapter(adapter);

	}

}
